package com.evenmo.poi;

import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFRow;
import org.apache.poi.hssf.usermodel.HSSFSheet;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;

/**
 * This is Description 导出Excel
 *
 * @author moyongjun
 * @date 2019/12/02
 */
public class OutputExcelDemo {
/**
* @author: moyongjun
* @Date: 2019/12/2 10:36 上午
* @Description: 从工作薄中写入数据到OutputExcelDemo.xls文件中
 * 07版本之前的写法
*
*/
    public void outputExcel(){

        //创建工作薄
        HSSFWorkbook workbook =new HSSFWorkbook();

        //常见工作表

        HSSFSheet sheet= workbook.createSheet("hello world");
        //创建工作行
       HSSFRow row= sheet.createRow(2);
        //创建单元格
        HSSFCell cell = row.createCell(2);

        cell.setCellValue("hello world");

        String fileName="OutputExcelDemo.xls";

        FileOutputStream fos= null;
        try {
            fos = new FileOutputStream(fileName);
        } catch (FileNotFoundException e) {
            System.out.println("请检测文件路径！");
            e.printStackTrace();
        }

        try {
            workbook.write(fos);
        } catch (IOException e) {
            e.printStackTrace();
        }
        try {
            workbook.close();
            System.out.println("导出完毕！");
        } catch (IOException e) {
            System.out.println("导出出现异常！");
            e.printStackTrace();

        }

    }

}
